﻿using MediatR;
using System.WXT.Infrstructre.Interface;
using System.WXT.WebAPI.Application.Command.CraftCommand;

namespace System.WXT.WebAPI.Application.CommandHandlers.CraftCommandHandlers
{
    public class CraftDeleteesCommandHandlers:IRequestHandler<CraftDeleteesCommand,int>
    {
        protected readonly ICraftRepository craftRepository;

        public CraftDeleteesCommandHandlers(ICraftRepository craftRepository)
        {
            this.craftRepository = craftRepository;
        }
        /// <summary>
        /// 工艺批量删除
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<int> Handle(CraftDeleteesCommand request, CancellationToken cancellationToken)
        {
            var list = (await craftRepository.GetAll()).Where(x=>request.craftManageId.Contains(x.craftManageId)).ToList();
            foreach (var item in list) 
            {
                item.craftManageIsDel = 1;
                await craftRepository.Update(item);
            }
            return 1;
            
            
        }
    }
}
